package org.example.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.example.common.response.ResponseData;
import org.example.entity.param.SalesmanParam;
import org.example.mapper.SalesmanMapper;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/salesman")
public class SalesmanController {
    @Resource
    SalesmanMapper salesmanMapper;
    @GetMapping("/query")
    public ResponseData query (SalesmanParam param){
        Wrapper qw = new QueryWrapper()
                .select("id","sale_name","password","sex","contact","sal")
                .like(StringUtils.isNotEmpty(param.getSaleName()),"sale_name",param.getSaleName())
                .eq(param.getContact()!=null,"contact",param.getContact())
                .ge(param.getLowSal()!=null && param.getHighSal()==null, "sal", param.getLowSal())
                .le(param.getLowSal()==null && param.getHighSal()!=null, "sal", param.getHighSal())
                .between(param.getLowSal()!=null && param.getHighSal()!= null
                        , "sal", param.getLowSal(),param.getHighSal());
        salesmanMapper.selectPage(param,qw);
        return ResponseData.success(param);
    }
}
